<template>
	<view class="content" @click="showHouseSelector = false">
		<popup :type="popupInfo.type" :popData="popupInfo.data" @toPage="toPage"></popup>
		<!-- 日记 -->
		<hm-follow-card
			ref="followCard"
			:options.sync="beautifulDiary"
			@show-activity="showActivity"
			@share="wxShare"
			@careSuccess="reloadActivityData"
		></hm-follow-card>
		<!-- icon -->
		<view class="padding-14" style="margin-bottom: 36rpx;margin-top: -70rpx;">
			<touch-grid-navigate shadowBar :list="appIconGetList" @click="goActivity" class="king-box"></touch-grid-navigate>
		</view>

		<!--swiper-->
		<view class="activity padding-14" style="margin-bottom: 36rpx;" v-if="appBannerGetList.length">
			<view class="appBannerBox">
				<carousel :img-list="appBannerGetList" url-key="bannerImgUrl" :odd="true" @selected="toActiveBanner"></carousel>
			</view>
			<image class="appBannerTy" src="//mall-rongchuang.oss-cn-beijing.aliyuncs.com/guixin_miniProgram/img/home/banner-ty.png"></image>
		</view>

		<!-- 探索 -->
		<view class="padding-14" style="margin-bottom: 36rpx;">
			<view class="explore">
				<view class="exploreTitle">
					<image class="exploreHeader" v-if="userInfo.avatar" :src="userInfo.avatar" mode="aspectFill"></image>
					<!--  #ifdef MP-WEIXIN -->
					<view v-else class="exploreHeader" style="overflow: hidden;"><open-data type="userAvatarUrl"></open-data></view>
					<!--  #endif -->
					<view class="exploreInfo">
						<h3>{{ userInfo.nickName }}</h3>
						<p v-if="userInfo.userType === 3">融创业主</p>
						<p v-else>融创会员</p>
					</view>
					<view class="exploreMore more white-more" open-type="navigate" @click="goExplore()">
						<view class="struct" style="font-size: 24rpx;"><text>探索更多</text></view>
					</view>
				</view>

				<view class="exploreBox" v-if="sysMedalTaskList.length > 0">
					<view class="exploreLi" v-for="(item, index) in sysMedalTaskList" :key="index">
						<image class="exploreLiHeader" :src="item.taskImgUrl"></image>
						<view class="exploreText">
							<h3>获得{{ item.medalName + item.medalLevelName }}勋章</h3>
							<p>
								<text>{{ item.taskName }}</text>
							</p>
						</view>
						<view style="position: relative;">
							<button @click="todoTask(item)" v-if="item.acceptTask == 0">{{ item.completeY }}</button>
							<button @click="todoTask(item)" v-else style="background-color: rgba(250, 204, 107, 0.5);">{{ item.completeN }}</button>
							<!-- 行动id item.nextActionId -->
							<view v-if="item.acceptTask != 0 && item.taskActionVos.length === 1 && item.taskActionVos[0].actionCount > 1" class="bar">
								<view class="num">{{ item.taskActionVos[0].doneCount }}/{{ item.taskActionVos[0].actionCount }}</view>
								<view class="progress">
									<view
										class="progress-inner"
										:style="{ transform: `scaleX(${item.taskActionVos[0].doneCount / item.taskActionVos[0].actionCount})` }"
									></view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 归心社群 -->
		<view style="margin-bottom: 36rpx;">
			<view class="titleBox padding-14"><h3>归心社群</h3></view>
			<view class="centering padding-14">
				<view
					v-for="(item, index) in communityList"
					:key="index"
					class="centeringImgSmall"
					:style="{
						height: index === 0 || index === 3 ? 216 + 'rpx' : 270 + 'rpx',
						width: index === 0 || index === 3 ? 143 + 'rpx' : 180 + 'rpx'
					}"
				>
					<image @click="communityHandle(item)" :src="item.portraitImgUrl" mode="aspectFit"></image>
				</view>
			</view>
		</view>
		<!-- 归心故事 -->
		<view v-if="sysContentInfoList.length > 0" style="margin-bottom: 36rpx;">
			<view class="titleBox padding-14">
				<h3>归心故事</h3>
				<view @click="returnStoreHandle()" class="titleMore more"><text>更多</text></view>
			</view>
			<view class="centeringStory padding-14">
				<view @click="storyDetailsHandle(item)" class="centeringStoryLi" v-for="(item, index) in sysContentInfoList" :key="index">
					<image :src="item.imgUrl"></image>
					<view class="tip" v-if="item.orgName">{{ item.orgName | dataFormat }}</view>
					<view>
						<h3>{{ item.contentName }}</h3>
						<p>{{ item.contentIntroduce }}</p>
					</view>
				</view>
			</view>
		</view>
		<!-- 热门活动 -->
<!-- 		<view v-if="swiperHotList.length > 0" style="margin-bottom: 36rpx;position: relative;">
			<view class="titleBox padding-14">
				<h3>热门活动</h3>
				<view @click="hotEvents" class="titleMore more"><text>更多</text></view>
			</view>
			<view class="appBannerBox"><carousel class="carousel" :img-list="swiperHotList" url-key="activityPic" @selected="toActive" /></view>
			<image
				class="appBannerTy carouselTy"
				src="//mall-rongchuang.oss-cn-beijing.aliyuncs.com/guixin_miniProgram/img/home/banner-ty.png"
			></image>
		</view> -->
		<!-- 主题打卡 -->
		<view v-if="sysThemePunchPlanList.length > 0" style="margin-bottom: 36rpx;position: relative;">
			<view class="titleBox padding-14">
				<h3>主题打卡</h3>
				<view @click="card" class="titleMore more"><text>更多</text></view>
			</view>

			<view class="appBannerBox">
				<carousel class="carousel" :img-list="sysThemePunchPlanList" url-key="imgUrl" label-key="planTheme" @selected="toTakeCard" />
			</view>
			<image
				class="appBannerTy carouselTy"
				src="//mall-rongchuang.oss-cn-beijing.aliyuncs.com/guixin_miniProgram/img/home/banner-ty.png"
			></image>
		</view>
		<!-- #ifdef H5 -->
		<!-- 调查问卷 -->
		<view v-if="questionList && questionList.length > 0">
			<view class="titleBox padding-14">
				<h3>调查问卷</h3>
				<view @click="questionMore" class="titleMore more"><text>更多</text></view>
			</view>
			<carousel-multi
				class="carousel-multi"
				:list="questionList"
				:base-width="256"
				:left="28"
				:right="28"
				:keys="{ imageUrlField: 'imgUrl', titleField: 'questionnaireName', dateTimeField: 'publishTime' }"
				@itemClick="questionnaireTo"
			></carousel-multi>
		</view>
		<!-- #endif -->
		<!-- 禁言 -->
		<uni-popup-slient ref="slient" :tip="title"></uni-popup-slient>

		<!-- 融创服务｜归心社群 -->
		<!-- #ifdef MP-WEIXIN -->
		<view class="footer">融创服务 | 聚友趣</view>
		<!-- #endif -->
		<drag-ball
			v-if="showSign"
			@signClick="signHandle"
			:imageBg="`//mall-rongchuang.oss-cn-beijing.aliyuncs.com/guixin_miniProgram/img/home/${isToday ? 'signed' : 'signIn'}.png`"
		></drag-ball>
		<my-fab-top :scrollTop="scrollTop"></my-fab-top>
		<uni-calendar
			@signSuccess="reloadActivityData"
			@fatherMethod="getMedalTaskData"
			:insert="false"
			:showMonth="false"
			ref="calendar"
			:lunar="false"
			:selected="selected"
			:isToday.sync="isToday"
			endDate="2099-12-31"
			@toPage="toPage"
			:num="numToday"
		></uni-calendar>
		<!-- 发布 -->
		<poster
			v-if="showPoster"
			ref="poster"
			:params.sync="poster"
			@share="showShare = true"
			@close="showPoster = false"
			:dirayId="beautifulDiary.diaryId"
		></poster>
		<popup-task ref="taskModule" @toFinish="goComplete"></popup-task>
	</view>
</template>

<script>
import http, { envVersion, freeRequest } from '@/common/request.js';
import HmFollowCard from '@/components/hm-follow-card/index.vue';
import carousel from '@/components/uni-carousel/uni-carousel';
import carouselMulti from '@/components/uni-carousel/uni-carousel-multi.vue';
import bridgeApi from '@/common/rayBridgeSDK.js';
import { mapState } from 'vuex';
import uniCalendar from '@/components/uni-calendar-other/uni-calendar.vue';
import dragball from '@/components/drag-ball/drag-ball.vue';
import myFabTop from '@/components/wppeng-top/wppeng-top.vue';
import Popup from '@/components/popup-activity/popup.vue';
import uniPopupSlient from '@/components/uni-popup/uni-popup-dialog-silent.vue';
import Poster from '@/components/ray-poster/poster.vue';
import { getLocationHref, getWxShareHref } from '@/common/utils.js';
import PopupTask from '@/components/uni-popup/popup-task.vue';
import TouchGridNavigate from '@/components/touch-grid-navigate/touch-grid-navigate.vue';
export default {
	components: {
		dragball,
		myFabTop,
		HmFollowCard,
		carousel,
		carouselMulti,
		uniCalendar,
		Popup,
		uniPopupSlient,
		Poster,
		PopupTask,
		TouchGridNavigate
	},
	created() {
		uni.$on('popScreenData', data => {
			this.popupInfo = { type: 'active', data };
		});
	},
	// #ifdef H5
	onShow() {
		this.getAllRequest();
	},
	// #endif
	watch: {
		location: {
			handler(val) {
				this.getAllRequest();
			},
			deep: true
		}
	},
	filters: {
		dataFormat(msg) {
			if (msg) {
				return msg.slice(0, 2);
			}
		}
	},
	computed: {
		...mapState({ userInfo: state => state.userInfo, location: state => state.location, currentHouse: state => state.currentHouse })
	},
	data() {
		// 获取当前日期
		var myDate = new Date().toDateString().split(' ');
		const date = [myDate[2], myDate[1], myDate[3]];
		return {
			popupInfo: {
				type: '',
				data: {}
			},
			showPoster: false,
			poster: {
				//主板版海报
				date,
				// #ifdef MP-WEIXIN
				path: getLocationHref({ go: '/interaction/diary/index' }),
				// #endif
				// #ifdef H5
				path: getWxShareHref({ go: '/interaction/diary/index' }),
				// #endif
				// // #ifdef MP-WEIXIN
				// path: getLocationHref({go: '/interaction/diary/view'}),
				// // #endif
				// // #ifdef H5
				// path: getWxShareHref({go: '/interaction/diary/view'}),
				// // #endif
				logoUrl: '',
				imageUrl: '',
				title: '',
				codeUrl: '',
				photoGrapher: '',
				userName: ''
			},
			isToday: false,
			selected: [],
			showSign: false,
			// 回到顶部
			scrollTop: 0,
			completeY: '去完成',
			completeN: '进行中',
			isInser: true,
			appIconGetList: [],
			// 日记
			beautifulDiary: {},
			// swiper
			appBannerGetList: [],
			// 社群
			communityList: [],
			//探索
			sysMedalTaskList: [],
			//归属故事
			sysContentInfoList: [],
			//主题打卡
			sysThemePunchPlanList: [],
			swiperCurrent: 0,
			// Hotswiper
			swiperHotList: [],
			questionList: [],
			swiperHotCurrent: 0,
			// Themeswiper
			swiperThemeCurrent: 0,
			// 签到
			isSigned: true,
			todoTaskList: {},
			showHonor: false,
			numToday: '',
			title: '云课堂正在建设中，请在小程序中搜索"聚友趣"观看',
			showRotate: false,
			rotateType: 5
		};
	},
	onPullDownRefresh() {
		this.getAllRequest();
		setTimeout(function() {
			uni.stopPullDownRefresh();
		}, 1000);
	},
	mounted() {
		uni.loadFontFace({
			family: 'din',
			source: 'url("https://mall-rongchuang.oss-cn-beijing.aliyuncs.com/guixin_miniProgram/fonts/PTDINCondensedCyrillic.ttf")',
			success() {}
		});
	},
	methods: {
		wxShare() {
			const {
				diaryContent: title,
				userName,
				imgUrl: imageUrl,
				qrCodeImgUrl: codeUrl,
				logoImgUrl: logoUrl,
				photographer: photoGrapher
			} = this.beautifulDiary;
			Object.assign(this.poster, { title, userName, imageUrl, codeUrl, logoUrl, photoGrapher });
			this.showPoster = true;
		},
		getAllRequest() {
			this.getNoAuthorRequest();
			if (this.userInfo.userId) {
				this.getAuthorRequest();
			}
			// #ifdef H5
			this.getAuthorRequest();
			// #endif
		},
		getNoAuthorRequest() {
			this.getBeautifulDiaryData();
			this.getIconData();
			this.getBannerData();
			this.getAssociationData();
			this.getContentInfoData();
			this.getActivityData();
			this.getThemeData();
			this.getSignData();
		},
		getAuthorRequest() {
			this.getMedalTaskData();
			this.showPopScreen();
			// #ifdef H5
			this.getQuestionData();
			// #endif
		},
		reloadActivityData() {
			setTimeout(r => this.getActivityData(), 1000);
		},
		showActivity({ popScreenList: data }) {
			this.popupInfo = { type: 'active', data };
		},
		toPage(value, type = 'medal') {
			if (type === 'medal') {
				http('/api/duiba/getNoLoginUrl?credits=0&redirect=' + value, { method: 'GET' }).then(result => {
					if (result.code == 200) {
						this.toWebView(result.data);
					}
				});
			} else if (type === 'question') {
				this.questionnaireTo({ questionnaireUrl: value });
			} else if (type === 'draw') {
				this.toActiveBanner({ bannerUrl: value, bannerUrlType: '1' });
			} else if (type === 'special') {
				this.toActive({ activityId: value });
			} else if (type === 'holiday') {
				this.toWebView(value);
			}
		},
		//监听页面滚动
		onPageScroll(res) {
			this.scrollTop = res.scrollTop;
		},
		signHandle() {
			this.getSignData();
			this.$refs.calendar.open();
		},
		async getSharePhoto() {
			const imageUrl = await this.$refs.poster.getSharePhoto();
			return { path: this.poster.path, title: this.beautifulDiary.diaryContent, imageUrl };
		},
		showPopScreen() {
			const isLoaded = uni.getStorageSync('popupLoaded');
			if (isLoaded) {
				return;
			}
			http('/api/sysPopScreen/indexPopScreen', { method: 'GET', data: {} }).then(result => {
				const data = result.data;
				if (result.code == 200 && data) {
					uni.setStorage({
						key: 'popupLoaded',
						data: true
					});
					this.popupInfo.data = data;
					this.popupInfo.type = { 2: 'special', 3: 'birthday', 4: 'holiday', 5: 'special', 6: 'draw', 7: 'question' }[data.popScreenType];
				}
			});
		},
		toActive({ activityId, activityName }) {
			//埋点
			this.$umaTrackEvent('activity', { activityId, activityName, source: '首页' });
			uni.navigateTo({
				url: '../../activity/info/index?activityId=' + activityId,
				animationType: 'pop-in',
				animationDuration: 200
			});
		},
		toTakeCard({ planId, planTheme }) {
			//埋点
			this.$umaTrackEvent('takeCard', { planId, planTheme, source: '首页' });
			uni.navigateTo({
				url: '/card/takeCard?id=' + planId,
				animationType: 'pop-in',
				animationDuration: 200
			});
		},
		toActiveBanner({ bannerUrl, bannerUrlType, urlFlag, taskVo, sysPartnerInfo }) {
			//埋点
			if (bannerUrlType !== 8) {
				this.$umaTrackEvent('home-banner', { bannerUrl, bannerUrlType, urlFlag, taskVo, source: '首页' });
			}
			let url = '';
			if (bannerUrlType === '1') {
				http('/api/duiba/getNoLoginUrl?credits=0&redirect=' + bannerUrl, { method: 'GET' }).then(result => {
					if (result.code == 200) {
						this.toWebView(result.data);
					}
				});
			} else if (['3', '4'].includes(bannerUrlType)) {
				this.toWebView(bannerUrl);
			} else if (bannerUrlType === '6') {
				if (urlFlag === '1') {
					this.toWebView(bannerUrl);
				} else {
					url = '../../home/community/biographyDetails?contentId=' + bannerUrl;
					uni.navigateTo({
						url,
						animationType: 'pop-in',
						animationDuration: 200
					});
				}
			} else if (bannerUrlType === '7') {
				// 拉新任务
				http('/api/sysMedalTask/todoTask', {
					method: 'POST',
					data: {
						medalTaskActionId: taskVo.medalTaskActionId,
						medalTaskId: taskVo.medalTaskId
					}
				}).then(result => {
					// uni.navigateTo({
					// 	url: '../../interaction/task/index',
					// 	animationType: 'pop-in',
					// 	animationDuration: 200
					// });
					uni.navigateTo({
						url: '../../personal/share',
						animationType: 'pop-in',
						animationDuration: 200
					});
				});
			} else if (bannerUrlType === '0') {
				// 拉新分享
				uni.navigateTo({
					url: '../../personal/share',
					animationType: 'pop-in',
					animationDuration: 200
				});
			} else if (['2', '5', '9'].includes(bannerUrlType)) {
				switch (bannerUrlType) {
					case '2':
						url = '../../activity/info/index?activityId=' + bannerUrl;
						break;
					case '5':
						url = '../../card/takeCard?id=' + bannerUrl;
						break;
					case '9':
						url = '../../home/returnHome/swiperDetails?recruitPartnerId=' + bannerUrl;
						break;
					default:
						break;
				}
				uni.navigateTo({
					url,
					animationType: 'pop-in',
					animationDuration: 200
				});
			} else if (bannerUrlType === '8') {
				if (sysPartnerInfo) {
					const { appId, applicationPagesPath: path, partnerType } = sysPartnerInfo;
					if (partnerType === '1') {
						wx.navigateToMiniProgram({ appId, path, envVersion, extraData: { uid: this.userInfo.userId } });
						//埋点
						wx.uma.trackEvent('home-banner', { bannerUrl, bannerUrlType, urlFlag, taskVo, appId, path, partnerType });
					} else {
						this.toWebView(path);
						//埋点
						wx.uma.trackEvent('home-banner', { bannerUrl, bannerUrlType, urlFlag, taskVo, path });
					}
				}
			}
		},
		//打卡
		getSignData() {
			http('/api/sysCheckDetails/checkList', {
				method: 'GET'
			}).then(res => {
				if (res.code == 200) {
					let result = [];
					this.numToday = res.data.num;
					res.data.data.map(item => {
						if (item.nowFlag == 0) {
							this.isToday = true;
						}
						result.push({
							date: item.check_time_str,
							nowFlag: item.nowFlag
						});
					});
					this.selected = result;
					this.showSign = true;
				}
			});
		},
		// icon图标
		getIconData() {
			freeRequest('/api/sysIconInfo/appIndexGetList', { method: 'GET', data: { iconLocation: 1, iconTerminal: 1 } }).then(result => {
				if (result.code == 200) {
					this.appIconGetList = result.data || [];
				}
			});
		},
		//banner
		getBannerData() {
			freeRequest('/api/sysBannerInfo/appIndexGetList', { method: 'GET', data: { bannerLocation: 1 } }).then(result => {
				if (result.code == 200) {
					this.appBannerGetList = result.data || [];
				}
			});
		},
		//社群
		getAssociationData() {
			freeRequest('/api/sysAssociationType/appIndexGetList', { method: 'GET' }).then(result => {
				this.communityList = result.data;
			});
		},
		//美好日记
		getBeautifulDiaryData() {
			freeRequest('/api/cusBeautifulDiary/appIndexGetList', { method: 'GET' }).then(result => {
				this.beautifulDiary = result.data || {};
			});
		},

		//勋章任务
		getMedalTaskData() {
			freeRequest('/api/sysMedalTask/appIndexGetList', { method: 'GET' }).then(result => {
				if (result.code == 200) {
					this.sysMedalTaskList = result.data || [];
					result.data.forEach((item, index) => {
						item.completeY = this.completeY;
						item.completeN = this.completeN;
					});
				}
			});
		},

		//归心故事
		getContentInfoData() {
			freeRequest('/api/sysContentInfo/appIndexGetList', { method: 'GET' }).then(result => {
				if (result.code == 200) {
					this.sysContentInfoList = result.data || [];
				}
			});
		},
		//活动
		getActivityData() {
			http('/api/activity/appActivityList', {
				method: 'GET',
				data: {
					pageNum: 1,
					pageSize: 3,
					type: 4
				}
			}).then(result => {
				if (result.code == 200) {
					if (result.data.length > 0) {
						this.swiperHotList = result.data;
					}
				}
			});
		},
		//主题打卡
		getThemeData() {
			freeRequest('/api/sysThemePunchPlan/appIndexGetList', { method: 'GET' }).then(result => {
				if (result.code == 200) {
					this.sysThemePunchPlanList = result.data || [];
				}
			});
		},
		//问卷
		getQuestionData() {
			http('/api/sysQuestionnaireInfo/getQuestionnaireInfo', { method: 'GET' }).then(result => {
				const list = result.data || [];
				for (let item of list) {
					item.publishTime = item.createTime.split(' ')[0] + ' 发布';
				}
				this.questionList = list;
			});
		},
		card() {
			//埋点
			this.$umaTrackEvent('takeCard-more', { source: '首页' });
			uni.navigateTo({
				url: '../../card/index',
				animationType: 'pop-in',
				animationDuration: 200
			});
		},
		goExplore() {
			//埋点
			this.$umaTrackEvent('todoTask-more', { source: '首页' });
			uni.navigateTo({
				url: '../../interaction/task/index',
				animationType: 'pop-in',
				animationDuration: 200
			});
		},
		swiperChange(e) {
			this.swiperCurrent = e.detail.current;
		},
		swiperHotChange(e) {
			this.swiperHotCurrent = e.detail.current;
		},
		swiperThemeChange(e) {
			this.swiperThemeCurrent = e.detail.current;
		},
		// 归心社区
		communityHandle({ associationId, associationName }) {
			//埋点
			this.$umaTrackEvent('home-community', { associationId, associationName, source: '首页' });
			uni.navigateTo({
				url: '/home/community/index?associationId=' + associationId + '&associationName=' + associationName,
				animationType: 'pop-in',
				animationDuration: 200
			});
		},
		// 归心故事详情
		storyDetailsHandle({ contentId, originalFlag, contentUrl, contentName }) {
			//埋点
			this.$umaTrackEvent('returnStorage', { contentId, contentName, contentUrl, source: '首页' });
			if (originalFlag === 0) {
				this.toWebView(contentUrl);
			} else {
				uni.navigateTo({
					url: '/home/returnStory/details?contentId=' + contentId,
					animationType: 'pop-in',
					animationDuration: 200
				});
			}
		},
		// 归心故事更多
		returnStoreHandle() {
			//埋点
			this.$umaTrackEvent('returnStorage-more', { source: '首页' });
			uni.navigateTo({
				url: '../../home/returnStory/index',
				success: res => {},
				fail: () => {},
				complete: () => {}
			});
		},
		//热门活动-更多
		hotEvents() {
			//埋点
			this.$umaTrackEvent('activity-more', { source: '首页' });
			// #ifdef MP-WEIXIN
			uni.switchTab({
				url: '../activity/index',
				animationType: 'pop-in',
				animationDuration: 200
			});
			// #endif
			// #ifdef H5
			// 不准把这个改掉，这是适配app的
			uni.navigateTo({
				url: '../activity/activity',
				animationType: 'pop-in',
				animationDuration: 200
			});
			// #endif
		},
		goActivity({ iconType, iconName, sysPartnerInfo }) {
			if (iconType == '5') {
				if (sysPartnerInfo) {
					const { appId, applicationPagesPath: path, partnerType } = sysPartnerInfo;
					if (partnerType === '1') {
						//埋点
						this.$umaTrackEvent('homeKings', { iconName, iconType, appId, appPath: path, source: '首页' });
						wx.navigateToMiniProgram({ appId, path, envVersion, extraData: { uid: this.userInfo.userId } });
					} else {
						//埋点
						this.$umaTrackEvent('homeKings', { iconName, iconType, webViewPath: path, source: '首页' });
						this.toWebView(path);
					}
				}
				return;
			} else if (iconType == '3') {
				//埋点
				this.$umaTrackEvent('homeKings', { iconName, iconType, source: '首页' });
				uni.navigateTo({
					url: '../../home/returnHome/index',
					animationType: 'pop-in',
					animationDuration: 200
				});
			} else if (iconType == '4') {
				//埋点
				this.$umaTrackEvent('homeKings', { iconName, iconType, source: '首页' });
				uni.navigateTo({
					url: '../../interaction/diary/list/index',
					animationType: 'pop-in',
					animationDuration: 200
				});
			} else if (iconType == '1') {
				//埋点
				this.$umaTrackEvent('homeKings', { iconName, iconType, source: '首页' });
				// #ifdef MP-WEIXIN
				uni.switchTab({
					url: '../activity/index',
					animationType: 'pop-in',
					animationDuration: 200
				});
				// #endif
				// #ifdef H5
				uni.navigateTo({
					url: '../activity/activity',
					animationType: 'pop-in',
					animationDuration: 200
				});
				// #endif
			} else if (iconType == '6') {//主题打卡 2022-02-28
				//埋点
				this.$umaTrackEvent('homeKings', { iconName, iconType, source: '首页' });
				uni.navigateTo({
					url: '../../card/index',
					animationType: 'pop-in',
					animationDuration: 200
				});
			} else if (iconType == '7') {//归心故事 2022-02-28
				//埋点
				this.$umaTrackEvent('homeKings', { iconName, iconType, source: '首页' });
				uni.navigateTo({
					url: '../../home/returnStory/index',
					animationType: 'pop-in',
					animationDuration: 200
				});
			}
		},
		todoTask(item) {
			const { actionId, acceptTask, medalName, medalTaskActionId, medalTaskId, taskName } = item;
			//埋点
			this.$umaTrackEvent('todoTask', { actionId, acceptTask, medalName, medalTaskActionId, medalTaskId, taskName, source: '首页' });
			if (item.acceptTask != 0 && item.taskActionVos.length > 1) {
				this.$refs.taskModule.open(item.taskActionVos, item.acceptTask);
			} else {
				this.goComplete(item);
			}
		},
		goComplete(item) {
			if (item.acceptTask == '0') {
				//此任务，当前用户未接取
				http('/api/sysMedalTask/todoTask', {
					method: 'POST',
					data: {
						medalTaskActionId: item.medalTaskActionId,
						medalTaskId: item.medalTaskId
					}
				})
					.then(result => {
						if (result.code == 200) {
							if (item.actionId == 1) {
								this.getSignData();
								this.$refs.calendar.open();
								item.completeY = '进行中';
								this.$refs.calendar.open();
							} else if (item.actionId == 2) {
								//跳转活动列表
								//#ifdef MP-WEIXIN
								uni.switchTab({
									url: '../../pages/activity/index',
									animationType: 'pop-in',
									animationDuration: 200
								});
								// #endif
								//#ifdef H5
								uni.navigateTo({
									url: '../../pages/activity/activity',
									animationType: 'pop-in',
									animationDuration: 200
								});
								//#endif
							} else if (item.actionId == 3) {
								//观看云课堂
								//跳转云课堂
								uni.navigateTo({
									url: '../../home/classRoom/index',
									animationType: 'pop-in',
									animationDuration: 200
								});
							} else if (item.actionId == 4) {
								//参与问卷
								//跳转问卷列表
								uni.navigateTo({
									url: '../../interaction/surveyList?medalTaskActionId=' + item.medalTaskActionId,
									// url: '../../personal/message',
									animationType: 'pop-in',
									animationDuration: 200
								});
							} else if (item.actionId == 5 || item.actionId == 6) {
								//评论
								//跳转评论页面
								//点赞
								//#ifdef MP-WEIXIN
								uni.switchTab({
									url: '/pages/interaction/index',
									animationType: 'pop-in',
									animationDuration: 200
								});
								//#endif
								//#ifdef H5
								uni.navigateTo({
									url: '../../card/index',
									animationType: 'pop-in',
									animationDuration: 200
								});
								//#endif
							} else if (item.actionId == 7) {
								//参与合伙人
								//跳转
								uni.navigateTo({
									url: '/home/returnHome/index',
									animationType: 'pop-in',
									animationDuration: 200
								});
							} else if (item.actionId == 8) {
								//拉新
								uni.navigateTo({
									url: '../../personal/share',
									animationType: 'pop-in',
									animationDuration: 200
								});
							}
						}
						this.getMedalTaskData();
					})
					.catch(r => {
						setTimeout(r => {
							this.goExplore();
						}, 1500);
					});
			} else {
				//此任务，当前用户已接取过
				if (item.actionId == 1) {
					//弹出签到层
					this.getSignData();
					this.$refs.calendar.open();
					item.completeY = '进行中';
					item.completeN = '进行中';
					this.$refs.calendar.open();
				} else if (item.actionId == 2) {
					//跳转活动列表
					//#ifdef MP-WEIXIN
					uni.switchTab({
						url: '../../pages/activity/index',
						animationType: 'pop-in',
						animationDuration: 200
					});
					// #endif
					//#ifdef H5
					uni.navigateTo({
						url: '../../pages/activity/activity',
						animationType: 'pop-in',
						animationDuration: 200
					});
					//#endif
				} else if (item.actionId == 3) {
					//观看云课堂
					//跳转云课堂
					uni.navigateTo({
						url: '../../home/classRoom/index',
						animationType: 'pop-in',
						animationDuration: 200
					});
				} else if (item.actionId == 4) {
					//参与问卷
					//跳转问卷列表
					uni.navigateTo({
						url: '../../interaction/surveyList?medalTaskActionId=' + item.medalTaskActionId,
						// url: '../../personal/message',
						animationType: 'pop-in',
						animationDuration: 200
					});
				} else if (item.actionId == 5 || item.actionId == 6) {
					//评论
					//跳转评论页面
					//点赞
					//#ifdef MP-WEIXIN
					uni.switchTab({
						url: '/pages/interaction/index',
						animationType: 'pop-in',
						animationDuration: 200
					});
					//#endif
					//#ifdef H5
					uni.navigateTo({
						url: '../../card/index',
						animationType: 'pop-in',
						animationDuration: 200
					});
					//#endif
				} else if (item.actionId == 7) {
					//参与合伙人
					//跳转参与合伙人
					uni.navigateTo({
						url: '/home/returnHome/index',
						animationType: 'pop-in',
						animationDuration: 200
					});
				} else if (item.actionId == 8) {
					//拉新
					uni.navigateTo({
						url: '../../personal/share',
						animationType: 'pop-in',
						animationDuration: 200
					});
				}
			}
		},
		questionMore() {
			//埋点
			this.$umaTrackEvent('question-more', { source: '首页' });
			uni.navigateTo({
				url: '../../interaction/surveyList',
				animationType: 'pop-in',
				animationDuration: 200
			});
		},
		questionnaireTo({ questionnaireUrl, questionnaireName }) {
			//埋点
			this.$umaTrackEvent('question', { questionnaireUrl, questionnaireName, source: '首页' });
			this.toWebView(questionnaireUrl);
		},
		toWebView(url) {
			// #ifdef H5
			location.href = url;
			// #endif
			// #ifdef MP-WEIXIN
			uni.navigateTo({
				url: '../../home/web_view?url=' + encodeURIComponent(url),
				animationType: 'pop-in',
				animationDuration: 200
			});
			// #endif
		},
		goUrl(url) {
			uni.navigateTo({
				url,
				animationType: 'pop-in',
				animationDuration: 200
			});
		}
	}
};
</script>
<style lang="less" scoped>
@import './index.css';

.padding-14 {
	padding-left: 28rpx;
	padding-right: 28rpx;
}

.bar {
	position: absolute;
	right: 0;
	transform: scale(0.5);
	transform-origin: top right;
	display: flex;
	align-items: center;
	justify-content: center;
	.num {
		font-size: 32rpx;
		color: #8a8c8d;
		margin-right: 12rpx;
	}
	.progress {
		height: 8rpx;
		border-radius: 8rpx;
		width: 260rpx;
		background-color: rgba(102, 100, 93, 0.2);
		.progress-inner {
			width: 100%;
			height: 8rpx;
			background-color: rgba(250, 204, 107, 1);
			transform: scaleX(0.5);
			transform-origin: left center;
		}
	}
}
</style>
